package oj;

/**
 * @author 郝文雪
 * @date 2022/8/18 15:13
 * @Description Test
 */
public class LC415 {
    public String addStrings(String num1, String num2) {
        if(num1.equals("0")){
            return num2;
        }
        if(num2.equals("0")){
            return num1;
        }
        int carry=0;
        StringBuilder sb=new StringBuilder();
        for(int i=num1.length()-1,j=num2.length()-1;i>=0||j>=0||carry!=0;i--,j--){
            int n1=i<0?0:num1.charAt(i)-'0';
            int n2=j<0?0:num2.charAt(j)-'0';
            int product=(n1+n2+carry)%10;
            sb.append(product);
            carry=(n1+n2+carry)/10;
        }
        return sb.reverse().toString();
    }
}
